<legend>Perfiles</legend>
<?php if (isset($this->mensaje["success"])) : ?>
    <?php $mensaje = $this->mensaje["success"][0] ?>
    <div class="alert alert-success alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <?php echo $mensaje->message ?>
    </div>
<?php endif; ?>
<?php if (isset($this->mensaje["error"])) : ?>
    <?php $mensaje = $this->mensaje["error"][0] ?>
    <div class="alert alert-error alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <?php echo $mensaje->message ?>
    </div>
<?php endif; ?>
<form name="form_registrar_permisos" method="POST" action="" >
    <input type="hidden" name="id" value="<?php echo $this->perfil->getId() ?>" />
<div class="row-fluid">
    <div class="well span12">
        <div class="span3">
            <div class="control-group">
                <label class="control-label" for="inputDescripcion">Descripción</label>
                <div class="controls">
                    <input id="inputDescripcion" name="descripcion" value="<?php echo $this->perfil->getDescripcion() ?>" type="text" class="input-large" />
                </div>
            </div>
            <label class="control-label" for="inputPerfil">Activar</label>
            <input type="hidden" name="activar" value="1" id="btn-activar" />
            <div class="btn-group" data-toggle="buttons-radio">
                <button id="activar_1" data-toggle="button" type="button" value="1" class="btn btn-info <?php echo $this->perfil->getActivo() == 1 ? "active" : "" ?>">Si</button>
                <button id="activar_2" data-toggle="button" type="button" value="0" class="btn btn-info <?php echo $this->perfil->getActivo() == 1 ? "" : "active" ?>">No</button>
            </div>
            <script type="text/javascript">
                var btns = ['activar_1', 'activar_2'];
                var input = document.getElementById('btn-activar');
                for(var i = 0; i < btns.length; i++) {
                    document.getElementById(btns[i]).addEventListener('click', function() {
                        input.value = this.value;
                    });
                }
            </script>
        </div>
        <div class="span1"></div>
        <div class="span8">
            <div class="btn-toolbar">
                <h4>Permisos</h4>
            <?php foreach ($this->permisos as $permiso) { ?>
                <?php 
                $permisosPerfil = $this->perfil->getPermisos();
                $check = "";
                if ($permisosPerfil->contains($permiso)) $check = "checked";
                ?>
                <div class="span3" style="margin-left:10px;">
                <label class="checkbox inline" style="margin-left:10px; word-break:keep-all;">
                    <input type="checkbox" id="inlineCheckbox1" name="permisos[]" value="<?php echo $permiso->getId() ?>" <?php echo $check ?> >
                    <?php echo $permiso->getDescripcion() ?>
                </label>
                </div>
            <?php } ?>
            </div>
        </div>
    </div>
    <div class="form-actions">
        <?php if ($this->perfil->getId()) : ?>
            <button type="submit" class="btn btn-warning" name="modificar">Modificar</button>
            <!--<button type="submit" class="btn btn-danger" name="eliminar">Eliminar</button>-->
            <a href="<?php echo $this->baseUrl("admin/usuario/permisos/") ?>" class="btn btn-primary">Cancelar</a>
        <?php else : ?>
            <button type="submit" class="btn btn-success" name="guardar">Guardar</button>
        <?php endif; ?>
    </div>
</div>
</form>

<div class="row-fluid">
        <table class="table table-bordered table-condensed">
            <thead>
                <tr>
                    <th style="width:60px;">#</th>
                    <th>Descripción</th>
                    <th style="width:50px;"></th>
                </tr>
            </thead>
            <?php if (count($this->perfiles)) : ?>
            <tbody>
                <?php foreach ($this->perfiles as $grupo) : ?>
                <tr>
                    <td style="text-align:center;"><?php echo $grupo->getId() ?></td>
                    <td><?php echo $grupo->getDescripcion() ?></td>
                    <td>
                        <a href="<?php echo $this->baseUrl("admin/usuario/permisos/id/".$grupo->getId()) ?>" class="btn btn-primary">Ver</a>
                    </td>
                </tr>
            </tbody>
            <?php endforeach; ?>
            <?php else : ?>
            <tbody>
                <tr>
                    <td class="5">Sin registros</td>
                </tr>
            </tbody>
            <?php endif; ?>
        </table>
</div>